{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd # type: ignore\n",
    "import Dats\n",
    "import sql_server\n",
    "import threading\n",
    "import os\n",
    "import win32com.client # type: ignore\n",
    "\n",
    "# Dataframe设置不显示小数点\n",
    "pd.set_option('display.precision', 0)\n",
    "\n",
    "sql_conn = None\n",
    "data_conn = None\n",
    "\n",
    "def sql():\n",
    "    global sql_conn\n",
    "    sql_conn = sql_server.main()\n",
    "\n",
    "def data():\n",
    "    global data_conn\n",
    "    data_conn = Dats.main()\n",
    "# 创建线程对象\n",
    "thread1 = threading.Thread(target=sql)\n",
    "thread2 = threading.Thread(target=data)\n",
    "\n",
    "# 启动线程\n",
    "thread1.start()\n",
    "thread2.start()\n",
    "\n",
    "# 等待线程结束\n",
    "thread1.join()\n",
    "thread2.join()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Summary_Table = pd.concat([data_conn, sql_conn], axis=1)\n",
    "output = Summary_Table.reindex(columns=[\n",
    "    '一级','二级','三级','四级','一级告警','二级告警','三级告警','四级告警',\n",
    "    '力维动环','数据库C接口','C接口',' ',\n",
    "    '维谛动环','数据库维谛接口','API'\n",
    "])\n",
    "output['IP地址'] = [\n",
    "    '212.11.36.214', '', '', '', '', '', '', '', '', '', '212.11.232.77', '',\n",
    "    '', '', '212.12.0.154', '212.11.246.77', '212.12.27.76', '', '',\n",
    "    '212.12.35.76', '212.12.38.77:33899', '', '', '', '', ''\n",
    "]\n",
    "wjj = os.getcwd()\n",
    "output['链接'] = [\n",
    "    '=HYPERLINK(\"' + f'{wjj}/bat/广州.bat' + '\",\"链接\")', '', '', '',\n",
    "    '=HYPERLINK(\"http://212.11.150.50/peim/views/login\")', '', '', '', '', '',\n",
    "    '=HYPERLINK(\"' + f'{wjj}/bat/湛江.bat' + '\",\"链接\")', '', '', '',\n",
    "    '=HYPERLINK(\"' + f'{wjj}/bat/清远.bat' + '\",\"链接\")',\n",
    "    '=HYPERLINK(\"' + f'{wjj}/bat/茂名.bat' + '\",\"链接\")',\n",
    "    '=HYPERLINK(\"' + f'{wjj}/bat/梅州.bat' + '\",\"链接\")', '', '',\n",
    "    '=HYPERLINK(\"' + f'{wjj}/bat/河源.bat' + '\",\"链接\")',\n",
    "    '=HYPERLINK(\"' + f'{wjj}/bat/汕尾.bat' + '\",\"链接\")', '',\n",
    "    '=HYPERLINK(\"http://212.11.9.1:8090/peim/views/default_design\")',\n",
    "    '=HYPERLINK(\"http://212.11.124.77:8090/peim\")', '', ''\n",
    "]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    # 获取 Excel 应用程序对象\n",
    "    excel = win32com.client.GetActiveObject('Excel.Application')\n",
    "    # 遍历所有打开的工作簿\n",
    "    for workbook in excel.Workbooks:\n",
    "        if workbook.Name == '3.0动环告警数量统计.xlsx':\n",
    "            # 关闭指定的工作簿\n",
    "            workbook.Close(SaveChanges=False)  # 如果需要保存更改，改为 SaveChanges=True\n",
    "            print('成功关闭工作簿: 3.0动环告警数量统计.xlsx')\n",
    "            break\n",
    "except:\n",
    "    pass\n",
    "output.to_excel(r'C:\\Users\\00\\Desktop\\3.0动环告警数量统计.xlsx',\n",
    "                sheet_name=\"sheet1\",\n",
    "                index=True,\n",
    "                header=True)\n",
    "print('转换成功！！！')\n",
    "xlsx = os.system(r\"start C:\\Users\\00\\Desktop\\3.0动环告警数量统计.xlsx\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
